﻿Public Class frmThongTinSanPham

    Private Sub frmThongTinSanPham_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lbTenSanPham.Text = frmQuanLyTapHoa.lbTenSanPham.Text
        Dim th As New TapHoa()
        th.m_strTenHangHoa = lbTenSanPham.Text
        Dim dt As DataTable = TapHoaDAO.LayThongTinMotSanPham(th)
        Dim lv As DataRow
        For Each lv In dt.Rows
            lbGia.Text = lv("hh_Gia").ToString()
            lbDonVi.Text = lv("dvt_Loai").ToString()
            lbSoLuong.Text = lv("hh_SoLuong").ToString()
            lbNhaCungCap.Text = lv("ncc_Ten").ToString()
            lbXuatXu.Text = lv("xx_NoiXuatXu").ToString()
            lbLoaiHang.Text = lv("lh_Loai").ToString()
            lbViTri.Text = lv("vt_NoiVT").ToString()
            picDaiDien.ImageLocation = lv("hh_HinhAnh").ToString()
        Next
    End Sub

    Private Sub btnMua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMua.Click
        If Integer.Parse(txtSoLuong.Text) > Integer.Parse(lbSoLuong.Text) Then
            MessageBox.Show("Trong kho không còn đủ số lượng cần mua")
            txtSoLuong.Focus()
            Return
        Else
            Dim TongTien As Integer
            Dim lvlDanhSachMua As Windows.Forms.ListView = Me.Tag
            Dim item As New ListViewItem()
            item.SubItems.Add(lbTenSanPham.Text)
            item.SubItems.Add(lbViTri.Text)
            item.SubItems.Add(txtSoLuong.Text)
            item.SubItems.Add(txtSoLuong.Text * lbGia.Text)
            TongTien = txtSoLuong.Text * lbGia.Text
            lvlDanhSachMua.Items.Add(item)
            frmQuanLyTapHoa.lbSoLuong.Text = Integer.Parse(frmQuanLyTapHoa.lbSoLuong.Text.ToString()) + Integer.Parse(txtSoLuong.Text.ToString())
            frmQuanLyTapHoa.lbTongTien.Text = Integer.Parse(frmQuanLyTapHoa.lbTongTien.Text.ToString()) + TongTien
        End If
    End Sub
End Class